/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bio.jpa.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Diego
 */
@Entity
@Table(name = "user", catalog = "biodb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findAllLessMe", query = "SELECT u FROM User u WHERE u.userId != :userId and u.userId != 1"),
    @NamedQuery(name = "User.findByUserId", query = "SELECT u FROM User u WHERE u.userId = :userId"),
    @NamedQuery(name = "User.findByUserLogin", query = "SELECT u FROM User u WHERE u.userLogin = :userLogin"),
    @NamedQuery(name = "User.findUsersInotIn", query = "select u from User u where  u.userId != 1 and u.userId not in (SELECT m.userHasGroupPK.uidFk  FROM UserHasGroup m where m.userHasGroupPK.gidFk=:grId) "),
    @NamedQuery(name = "User.findMyUsers", query = "select u from User u where u.userId in (SELECT m.userHasGroupPK.uidFk  FROM UserHasGroup m where m.userHasGroupPK.gidFk=:grId) "),
    @NamedQuery(name = "User.Auth", query = "SELECT u FROM User u WHERE u.userLogin = :userLogin and  u.userPass = :userPass"),
    @NamedQuery(name = "User.findAssignedProjects", query = " select p from Project p where p.prjId in (SELECT m.projectHasUserPK.projectPrjId  FROM ProjectHasUser m where m.projectHasUserPK.userUserId=:userId) "),
    @NamedQuery(name = "User.findByUserEmail", query = "SELECT u FROM User u WHERE u.userEmail = :userEmail"),
    @NamedQuery(name = "User.findUsersNotInProject", query = " select u from User u where u.userId != 1 and u.userId not in (SELECT m.projectHasUserPK.userUserId  FROM ProjectHasUser m where m.projectHasUserPK.projectPrjId=:prjId ) "),
    @NamedQuery(name = "User.findByUserPass", query = "SELECT u FROM User u WHERE u.userPass = :userPass"),
    @NamedQuery(name = "User.findByUserCreation", query = "SELECT u FROM User u WHERE u.userCreation = :userCreation"),
    @NamedQuery(name = "User.findByUserLive", query = "SELECT u FROM User u WHERE u.userLive = :userLive")})
public class User implements Serializable {
    @OneToMany(mappedBy = "createdBy")
    private List<Fasta> fastaList;
    @Basic(optional =     false)
    @NotNull
    @Column(name = "user_creation")
    @Temporal(TemporalType.TIMESTAMP)
    private Date userCreation;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic(optional = false)
    @Column(name = "user_id")
    private Integer userId;
    @Basic(optional = false)
    @Size(min = 1, max = 45)
    @Column(name = "user_login")
    private String userLogin;
    @Basic(optional = false)
    @Size(min = 1, max = 45)
    @Column(name = "user_email")
    private String userEmail;
    @Basic(optional = false)
    @Size(min = 1, max = 45)
    @Column(name = "user_pass")
    private String userPass;
    @Basic(optional = false)
    @Column(name = "user_live")
    private boolean userLive;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<ProjectHasUser> projectHasUserCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private Collection<Project> projectCollection;
    @OneToMany(mappedBy = "updatedBy")
    private Collection<Project> projectCollection1;
    @OneToMany(mappedBy = "createdBy")
    private Collection<GenBank> genBankCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Session> sessionCollection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "user")
    private UserPrevilege userPrevilege;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private List<UserHasGroup> userHasGroupList;

    public User() {
    }

    public User(Integer userId) {
        this.userId = userId;
    }

    public User(Integer userId, String userLogin, String userEmail, String userPass, Date userCreation, boolean userLive) {
        this.userId = userId;
        this.userLogin = userLogin;
        this.userEmail = userEmail;
        this.userPass = userPass;
        this.userCreation = userCreation;
        this.userLive = userLive;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserLogin() {
        return userLogin;
    }

    public void setUserLogin(String userLogin) {
        this.userLogin = userLogin;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserPass() {
        return userPass;
    }

    public void setUserPass(String userPass) {
        this.userPass = userPass;
    }

    public Date getUserCreation() {
        return userCreation;
    }

    public void setUserCreation(Date userCreation) {
        this.userCreation = userCreation;
    }

    public boolean getUserLive() {
        return userLive;
    }

    public void setUserLive(boolean userLive) {
        this.userLive = userLive;
    }

    @XmlTransient
    public Collection<ProjectHasUser> getProjectHasUserCollection() {
        return projectHasUserCollection;
    }

    public void setProjectHasUserCollection(Collection<ProjectHasUser> projectHasUserCollection) {
        this.projectHasUserCollection = projectHasUserCollection;
    }

    @XmlTransient
    public Collection<Project> getProjectCollection() {
        return projectCollection;
    }

    public void setProjectCollection(Collection<Project> projectCollection) {
        this.projectCollection = projectCollection;
    }

    @XmlTransient
    public Collection<Project> getProjectCollection1() {
        return projectCollection1;
    }

    public void setProjectCollection1(Collection<Project> projectCollection1) {
        this.projectCollection1 = projectCollection1;
    }

    @XmlTransient
    public Collection<GenBank> getGenBankCollection() {
        return genBankCollection;
    }

    public void setGenBankCollection(Collection<GenBank> genBankCollection) {
        this.genBankCollection = genBankCollection;
    }

    @XmlTransient
    public Collection<Session> getSessionCollection() {
        return sessionCollection;
    }

    public void setSessionCollection(Collection<Session> sessionCollection) {
        this.sessionCollection = sessionCollection;
    }

    public UserPrevilege getUserPrevilege() {
        return userPrevilege;
    }

    public void setUserPrevilege(UserPrevilege userPrevilege) {
        this.userPrevilege = userPrevilege;
    }

    @XmlTransient
    public List<UserHasGroup> getUserHasGroupCollection() {
        return userHasGroupList;
    }

    public void setUserHasGroupList(List<UserHasGroup> userHasGroupList) {
        this.userHasGroupList = userHasGroupList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bio.jpa.entities.User[ userId=" + userId + " ]";
    }

    @XmlTransient
    public List<Fasta> getFastaList() {
        return fastaList;
    }

    public void setFastaList(List<Fasta> fastaList) {
        this.fastaList = fastaList;
    }

}
